<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Water Login Page</title>

  <style>
    body {
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      background-color: #2A3F54;
    }

    .login-container {
      width: 300px;
      padding: 20px;
      background-color: #ffffff;
      border-radius: 10px;
      box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
      text-align: center;
    }

    .water-shape {
      width: 150px;
      height: 150px;
      overflow: hidden;
      margin: 10px auto;
      background-image: url('./public/img/260.jpg');
      /* Replace with your water image */
      background-size: cover;
      background-position: center;
      /* transition: transform 0.9s ease-in-out; */
      transition: border-radius 1.5s ease-in-out;

    }

    .water-shape.active {
      /* transform: translateX(150px); */
      border-radius: 50%;
    }
  </style>
</head>

<body>
  <div id="app">
    <div class="login-container">
      <div class="water-shape"></div>
      <form @submit.prevent="submitForm">
        <input v-model="username" type="text" placeholder="Username">
        <input v-model="password" type="password" placeholder="Password">
        <p><button type="submit">Login</button>
      </form>
    </div>
  </div>
  <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script> -->

  <!-- 引入vue -->


  <script>

    const waterShape = document.querySelector('.water-shape');
    const form = document.querySelector('form');
    const formInputs = document.querySelectorAll('input');

    formInputs.forEach(input => {
      input.addEventListener('focus', () => {
        waterShape.classList.add('active');
      });

      input.addEventListener('blur', () => {
        waterShape.classList.remove('active');
      });
    });

    form.addEventListener('submit', function (event) {
      event.preventDefault();

      const username = formInputs[0].value;
      const password = formInputs[1].value;

      console.log('username=', username);

      if (username === '123' && password === '123') {

        // 优化显示    登录成功状态  存入浏览器缓存
        localStorage.setItem("login_is", 1);
        localStorage.setItem("username", username);
        // 登录成功 实现跳转
        window.location.href = 'indexs.html';
        alert("login success")
        // res.json({ valid: true });
      } else {
        localStorage.setItem("login_is", 0);

        alert("Invalid credentials. Please try again")

        // res.json({ valid: false });
      }

    });
    //实现在当前目录下和app，js的信息交互 
    const app = new Vue({
      el: '#app',
      data: {
        username: '',
        password: ''
      },
      methods: {
        submitForm() {
          const username = this.username;
          const password = this.password;
          console.log('username=', username);
          if (username === '123' && password === '123') {
            // 登录成功 实现跳转
            window.location.href = 'indexs.html';

            res.json({ valid: true });
          } else {
            alert("Invalid credentials. Please try again")
            res.json({ valid: false });
          }
        }
      }
    })


  </script>

</body>

</html>